﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using System.ComponentModel;
using System.Windows.Browser;

namespace Quebec.Silverlight.Behaviors
{
public class AnalyticsAction : TargetedTriggerAction<FrameworkElement>
{
	[Category("Target Properties")]
	public string JavaScriptMethod
	{
		get { return (string)GetValue(JavaScriptMethodProperty); }
		set { SetValue(JavaScriptMethodProperty, value); }
	}
	public static readonly DependencyProperty JavaScriptMethodProperty =
		 DependencyProperty.Register("JavaScriptMethod", typeof(string), typeof(AnalyticsAction), new PropertyMetadata("dcsMultiTrack"));

	[Category("Target Properties")]
	public string Category
	{
		get { return (string)GetValue(CategoryProperty); }
		set { SetValue(CategoryProperty, value); }
	}
	public static readonly DependencyProperty CategoryProperty =
		 DependencyProperty.Register("Category", typeof(string), typeof(AnalyticsAction), null);

	protected override void Invoke(object parameter)
	{
		if (Target == null)
			return;

		if (string.IsNullOrEmpty(JavaScriptMethod))
			JavaScriptMethod = "trackEvent";

		HtmlPage.Window.Invoke(JavaScriptMethod, new object[] { Category });
	}
}
}
